package com.example.util.handler;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;

/**
 * @program: sms
 * @description:
 * @author: zhanghz001
 * @create: 2020-11-09 20:13
 **/
public class ScalarHandler<T> implements ResultSetHandler<T> {
    //实现类3：用于返回一个聚合函数的查询结果

    @Override
    public Long handler(ResultSet rs) {
        Long result = null;
        try {
            if (rs.next()) {
                ResultSetMetaData rsmd = rs.getMetaData();
                int columnCount = rsmd.getColumnCount();
                String columnName = rsmd.getColumnName(1);
                result = rs.getLong(columnName);
                return result;

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

        }
        return result;
    }
}
